package com.hliushi.webui.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


@Mapper
@Repository
public interface CovidMapper {


    /**
     * 查询全国疫情汇总数据
     *
     * @param datetime 时间
     * @return
     */
    @Select("select `datetime`, `currentConfirmedCount`, `confirmedCount`, `suspectedCount`, `curedCount`, " +
            "`deadCount` from covid19_1 where `datetime` = #{datetime}")
    List<Map<String, Object>> getNationalData(String datetime);


    /**
     * 查询全国各省份疫情累计确诊数据
     * #
     * var dataList = [
     * .        {name: '北京', value: 100},
     * .        {name: '上海', value: randomValue()}
     * ]
     * provinceShortName as name, confirmedCount as value 这里把查询出来的字段重命名, 为了和前端保持一致
     *
     * @param datetime 时间
     * @return 省份名称, 累计确诊数
     */
    @Select("select provinceShortName as name, confirmedCount as value FROM covid19_2 " +
            "where datetime = #{datetime}")
    List<Map<String, Object>> getNationalMapData(String datetime);


    /**
     * 查询全国每一天的疫情数据
     * #
     * dataset: {
     * .            // 这里指定了维度名的顺序，从而可以利用默认的维度到坐标轴的映射。
     * .            dimensions: ['dateId', '新增确诊', '累计确诊', '疑似病例', '累计治愈', '累计死亡'],
     * .            source: []
     * .        }
     *
     * @return dateId, confirmedIncr, confirmedCount, suspectedCount, curedCount, deadCount
     */
    @Select("select dateId, confirmedIncr as `新增确诊`, confirmedCount as `累计确诊`, suspectedCount as `疑似病例`, curedCount as `累计治愈`," +
            " deadCount as `累计死亡` from covid19_3")
    List<Map<String, Object>> getCovidTimeData();


    /**
     * 查询各省份境外输入病例数量
     *
     * @param datetime 时间
     * @return provinceShortName as name, confirmedCount as value
     */
    @Select("select provinceShortName as name, confirmedCount as value from covid19_4 where datetime = #{datetime} " +
            "order by `value` desc limit 10")
    List<Map<String, Object>> getCovidImportData(String datetime);


    /**
     * 查询各物资使用情况
     *
     * @return dimensions: ['name', '采购', '下拨', '捐赠', '消耗', '需求', '库存']
     */
    @Select("select `name`, `cg` as '采购', `xb` as '下拨', `jz` as '捐赠', `xh` as '消耗', `xq` as '需求', `kc` as '库存' from covid19_wz")
    List<Map<String, Object>> getCovidWz();
}
